package com.shop.controller;

import com.shop.pojo.pms.Pms_Category;

import com.shop.service.AttrGroupCatalogVoService;
import com.shop.service.Pms_Category_Service;

import com.shop.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/category")
public class Pms_Category_Controller {
    @Autowired
    private Pms_Category_Service pms_category_service;
    @Autowired
    private AttrGroupCatalogVoService attrGroupCatalogVoService;


    /*
     * @Description 查找全部分类，返回是tree类型的，供前台layui使用
     * @param
     * @return java.util.List<com.shop.vo.CatalogByTree>
     * @author liusupeng
     * @date 2020/10/27 13:20
     */
    @GetMapping("/getTree")
    public R pms_categoryList(){

        R r=new R();
        r.data(pms_category_service.getTree());
        return r;
    }
//前台查询三级分类以及品牌
    @GetMapping("/getHomeTree")
    public R getHomeTree(){
        R r=new R();
        r.data(pms_category_service.getHomeTree());
        return r;
    }
    /*
     * @Description 查询第三层的分类
     * @param
     * @return com.shop.utils.R
     * @author liusupeng
     * @date 2020/11/1 22:24
     */
    @GetMapping("/getCategoryByThree")
    public R getCategoryByThree(){

        return pms_category_service.getCategoryByThree();
    }
    /*
     * @Description 查询全部分类、分组、属性
     * @param
     * @return java.lang.Object
     * @author liusupeng
     * @date 2020/10/29 12:46
     */
    @GetMapping("/getAttrGroupCatalogvo")
    public Object getAttrGroupCatalogvo(Integer cat_id){
            System.out.println(cat_id);
        return attrGroupCatalogVoService.ATTR_GROUP_CATALOG_VO(cat_id);
    }
    /*
     * @Description 添加一条商品分类
     * @param category
     * @return com.shop.utils.R
     * @author liusupeng
     * @date 2020/10/29 8:53
     */
    @PostMapping("/addCategory")
    public R addCategory(Pms_Category category){


        return pms_category_service.addCatalog(category);
    }
    /*
     * @Description 修改一条商品分类
     * @param category
     * @return com.shop.utils.R
     * @author liusupeng
     * @date 2020/10/29 8:53
     */
    @PutMapping("/updateCategory")
    public R updateCategory(Pms_Category category){


        return pms_category_service.updateCatalog(category);
    }
    @DeleteMapping("/delCategoryByCatelogId")
    public R delCategory(Integer catelogId){

        return pms_category_service.delCatalog(catelogId);
    }
}
